<template>
    <form>
      <table>
        <tr>
          <td>品牌</td>
          <td>
            <select v-model="car.tid">
              <option :value="type.id" v-for="(type,index) in typeList":key="index">{{type.name}}</option>
            </select>
          </td>
        </tr>
        <tr>
          <td>型号</td>
          <td><input type="text" v-model="car.name"/></td>
        </tr>
        <tr>
          <td>价格</td>
          <td><input type="text" v-model="car.price"/></td>
        </tr>
        <tr>
          <td>速度</td>
          <td><input type="text" v-model="car.speed"/></td>
        </tr>
        <tr>
          <td>生产日期</td>
          <td><input type="date" v-model="car.createDate"/></td>
        </tr>
        <tr><td colspan="2"><button @click.prevent="addCar()">添加</button></td> </tr>
      </table>
    </form>
</template>

<script>
    export default {
      name: "InsertCar",
      data(){
        return{
          car:{},
          typeList:[]
        }
      },
      methods:{
        addCar(){
          this.axios({
            method:"get",
            url:"/car/insertCar.do",
            params:this.car
          }).then((res)=>{
            alert("添加成功")
            this.$router.push("/")
          })
        }
      },
      created() {
        this.axios({
          method:"get",
          url:"/carType/selectAllType.do"
        }).then((res)=>{
          this.typeList=res.data
        })
      }
    }
</script>

<style scoped>

</style>
